package com.fjxd.user.service.impl;

import com.fjxd.feign.result.ViewResult;
import com.fjxd.user.mapper.UserMapper;
import com.fjxd.user.pojo.User;
import com.fjxd.user.service.RegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class RegisterServiceImpl implements RegisterService {
    @Autowired
    private UserMapper userMapper;
    /*
     * 用户注册
     * */
    @Override
    public ViewResult insertUser(User u) {
        User selectOne = userMapper.findUserByUserAndPwd(u);
        if (selectOne==null)
        {
            String name=u.getUsername();
            String pwd=u.getPassword();
            User user=new User();
            user.setId(null);
            user.setUsername(name);
            user.setPassword(pwd);
            userMapper.insert(user);
            return ViewResult.success(user);
        }
        else {
            return new ViewResult(ViewResult.Status.INUSER.getCode(), ViewResult.Status.INUSER.getMessage());
        }

    }
}
